﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

[ExecuteInEditMode]
public class CanvasRefiner : MonoBehaviour {
    public CanvasScaler canvasScaler;

    private void Update()
    {
        float heightMin = 2200, heightMax = 2727;
        float widthMin = 3.46f, widthMax = 2.76f;
        float height;
        float width = Camera.main.orthographicSize * Camera.main.aspect;

        if (width > widthMin) height = heightMin;
        else if (width < widthMax) height = heightMax;
        else
        {
            height = (width - widthMin) * (heightMin - heightMax) / (widthMin - widthMax) + heightMin;
        }

        canvasScaler.referenceResolution = new Vector2(canvasScaler.referenceResolution.x, height);
    }
}
